/**
 * com.dingjian.framework.compoment.WorkBenchController.java
 */
package com.dingjian.framework.compoment;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dingjian.base.util.StringUtils;
import com.dingjian.basedata.org.model.Org;
import com.dingjian.basedata.org.model.Position;
import com.dingjian.basedata.person.model.Person;
import com.dingjian.framework.base.controller.BaseController;
import com.dingjian.permission.model.Menu;

/**
 * @author FengMy
 * 
 * @since 2012-9-12
 */
@Controller
public class WorkBenchController extends BaseController {
	
	@RequestMapping(value="workbench")
	public String workBench(ModelMap model){
		String workbench = getString("workbench");
		if(StringUtils.isEmpty(workbench)){
			workbench = (String) getSession().getAttribute("workbench");
			if(StringUtils.isEmpty(workbench)){
				workbench = "simple";
			}
		}
		Person person = (Person) getSession().getAttribute("LOGIN-USER");
		Position position = (Position) getSession().getAttribute("CURRENT-POSITION");
		Org org = (Org) getSession().getAttribute("CURRENT-ORG");
		model.put("person", person);
		model.put("position", position);
		model.put("org", org);
		model.put("menus", getMenu());
		return "framework/workbench_" + workbench;
	}
	
	private List<Menu> getMenu(){
		Map<String, Object> param = new HashMap<String, Object>();
		List<Menu> menus = queryExecutor.execQuery("com.dingjian.permission.dao.MenuDao.getChild", param , Menu.class);
		for(Menu m : menus){
			param.put("longNumber", m.getLongNumber());
			m.setChildren(queryExecutor.execQuery("com.dingjian.permission.dao.MenuDao.getChild", param, Menu.class));
		}
		return menus;
	}
}
